package com.tianshi.user.mapper;

import com.tianshi.entity.Users;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    //根据关键字查询用户是否存在
    @Select("SELECT * FROM users WHERE username=#{keyword} or phone = #{keyword}")
    Users selectByKeyword(String keyword);
    //用户注册
    @Insert("INSERT INTO users(username, password, phone, email, user_type, created_at) VALUES(#{username}, #{password}, #{phone}, #{email}, #{userType},#{createdAt})")
    int insert(Users user);

    //根据手机号查询用户
    @Select("SELECT * FROM users WHERE phone = #{phone}")
    Users selectByPhone(String phone);

    //根据用户id查询用户信息
    @Select("SELECT * FROM users WHERE user_id = #{userId}")
    Users selectByUserId(Long userId);

    //更新用户信息
    @Update("UPDATE users SET username = #{username}, email = #{email}, phone = #{phone}, user_type = #{userType} WHERE user_id = #{userId}")
    void updateUserInfo(Users user);

    //更新用户密码
    @Update("UPDATE users SET password = #{password} WHERE user_id = #{userId}")
    void updateUserPassword(Users user);
}
